<?php
class Admin_Model_ProCategory extends Zend_Db_Table_Abstract
{
	protected $_name="product_category";
	public function getAllCategory()
	{
		$db=Zend_Registry::get('connectDB');
		$select=$db->select()->from($this->_name);
		//$select->where('product.status = 1');
		//$langId = My_Translate::getLanguage();
		//$select->where('product_category.languageId = '.$langId);
		//$select->joinLeft('product_category', 
				//	'product_category.categoryId=product.categoryId', array('categoryName'));
		//$select->joinLeft('user', 
					//'user.userId=product.createdBy', array('userName'));
		//$select->order("RAND()")->limit($num);
		return $select->query()->fetchAll();
		
	}
	public function getIdNameCategory()
	{
		$db=Zend_Registry::get('connectDB');		
		$categoryIdList = $this->loadCol('categoryId');
		$categoryNameList = $this->loadCol('categoryName');		
		array_unshift($categoryIdList,0);
		array_unshift($categoryNameList,"- Select Category -");				
		return array_combine($categoryIdList,$categoryNameList);
		 
	}
	public function loadCol($column)
	{		
		return $this->getAdapter()->fetchCol("select $column from product_category");
	}
	//
	//vietslbfow
	//

 	public function lists()
	{
 		$db=Zend_Registry::get('connectDB');
		$sql=$db->select()->from($this->_name);
		
		$result=$db->fetchAll($sql);
		return $result;
	}
 	public function NewCategory($categoryName,$description,$imageURL,$languageId)
	{
		$row = $this->createRow();
		$row->categoryName=$categoryName;
		$row->description=$description;
		$row->imageURL=$imageURL;
		$row->languageId=$languageId;
		$row->save();
		$id = $this->_db->lastInsertId();
		return $id;
	}
	public function UpdateCategory($id,$categoryName,$description,$languageId,$imageURL)
	{
		$row = $this->find($id)->current();
		if($row)
		{
			$row->categoryName=$categoryName;
			$row->description=$description;
			$row->imageURL=$imageURL;
			$row->languageId=$languageId;
			$row->save();
		}
	}
 	public function deletePage($id)
	{
		$row = $this->find($id)->current();
		if($row) $row->delete();
	}
						
 	public function getCategory($id)
	{
		$select=$this->select()->where('categoryId =?',$id);
		$row = $this->fetchRow($select);
		if($row) return $row;
	}
	
}